package com.xyz.util;

import cn.hutool.core.io.FileUtil;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MybatisGenerator {

    // 手动生成数据库entity
    public static void main(String[] args) {
        try {
            MybatisGenerator.mybatisGenerator();
        } catch (Exception e) {
            System.out.println(e.getLocalizedMessage());
        }
    }

    public static void mybatisGenerator() throws Exception {
        FileUtil.del(new File("src/main/java/com/xyz/entity"));
        List<String> warnings = new ArrayList<>();
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(new File("src/main/resources/generatorConfig.xml"));
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }

}
